package com.atguigu.testdemo;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

public class TestJDBC {
    @Test
    public void test1(){
        DruidPooledConnection connection=null;
        ApplicationContext context=new ClassPathXmlApplicationContext("jdbc.xml");
        DruidDataSource dataSource = context.getBean("dataSource", DruidDataSource.class);
        try {
            connection= dataSource.getConnection();
            System.out.println(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }

}
